package com.gz.rocketmq.delay;


import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * 延时消息  生产
 */
public class DelayProducer {


    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("delay_group");
        producer.setNamesrvAddr("192.168.36.128:9876");
        producer.start();

        for (int i = 0; i < 10; i++) {
            Message message = new Message("delayTopic","delayTag",("测试延迟"+i).getBytes(StandardCharsets.UTF_8));
           //1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
            message.setDelayTimeLevel(2);
            SendResult send = producer.send(message);
            System.out.println(send);
        }

        producer.shutdown();
    }
}
